import React, {useState,useEffect} from "react";
import {Modal } from "antd/lib";
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper";
import DynamicComponent from "@/components/DynamicComponent";
import {UserProfile} from "@/components/proptypes";
import {BrowserRouter as Router, Link} from "react-router-dom";
import {createBrowserHistory} from 'history'
const customHistory = createBrowserHistory();

function CreateOrgUnitDialog({ items, dialog }) {
  const [id, setid] = useState(0);
  // const [code, setcode] = useState("");
  const [billname, setbillname] = useState("");
  // const [saveInProgress, setSaveInProgress] = useState(false);
  useEffect(() => {
    if (items.id === 0) return;
      setid(items.id);
      // setcode(items.code);
      setbillname(items.billname);
  }, [items]);

  function handleSubmit() {
      dialog.close({ success: true});
  }

  return (
    <Modal
      {...dialog.props}
      {...({ footer: null })}
      title={billname}
      okText="确定"
      cancelText="取消"
      okButtonProps={{
     //   disabled: !isValid || saveInProgress,
    //    loading: saveInProgress,
        "data-test": "DashboardSaveButton",
      }}
      cancelButtonProps={{
        disabled: false,
      }}
      onOk={handleSubmit}
      // closable={!saveInProgress}
      // maskClosable={!saveInProgress}
      wrapProps={{
        "data-test": "CreateDashboardDialog",
      }}>
      <DynamicComponent name="CreateOrgUnitDialogExtra" >
          <Router  history={customHistory}>
            <Link to={`/contract/apply/new/${id}`}>打开{billname}</Link>
           </Router>
        {/*<a href='contract/change/new/'{id}>打开{billname}</a>*/}
      </DynamicComponent>
    </Modal>
  );
}

CreateOrgUnitDialog.propTypes = {
  items: UserProfile.isRequired,
  dialog: DialogPropType.isRequired,
};

export default wrapDialog(CreateOrgUnitDialog);
